<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="layui-col-xs6 layui-col-md4">
    <div>
        <img src="/images/default.gif" style="width: 155px;height: 225px;margin: 30px;">
        <br>
        <span>
      <img src="/images/borrowed.png">
      <span>借阅：</span>
      <span th:text="${borrow}"></span>
    </span>
        <span>
      <img src="/images/favorite_yes.png">
      <span>收藏：</span>
      <span th:text="${star}"></span>
    </span>
    </div>
</div>
<div class="layui-col-xs12 layui-col-md8">
    <table class="layui-table" lay-even="" lay-skin="nob">
        <colgroup>
            <col width="150">
            <col width="150">
            <col>
        </colgroup>
        <tbody>
        <tr style="font-weight: 700;">
            <td>书名</td>
            <td th:text="${books.getName()}">无</td>
        </tr>
        <tr>
            <td>别名</td>
            <td th:text="${books.getAlias()}">无</td>
        </tr>
        <tr>
            <td>作者</td>
            <td th:text="${books.getAuthor()}">无</td>
        </tr>
        <tr>
            <td>ISBN</td>
            <td th:text="${books.getISBN()}">无</td>
        </tr>
        <tr>
            <td>中图号</td>
            <td th:text="${books.getClassification()}">无</td>
        </tr>
        <tr>
            <td>出版社</td>
            <td th:text="${books.getPublishingHouse()}">无</td>
        </tr>
        <tr>
            <td>出版年份</td>
            <td th:text="${books.getPublishDate()}">无</td>
        </tr>
        <tr>
            <td>上架日期</td>
            <td th:text="${books.getDate()}">无</td>
        </tr>
        <tr>
            <td>评分</td>
            <td th:text="${books.getScore()}">无</td>
        </tr>
        <tr>
            <td>简介</td>
            <td th:text="${books.getIntro()}">无</td>
        </tr>
        </tbody>
    </table>
</div>
<input type="hidden" th:value="${books.getName()}" id="bookName">
<input type="hidden" th:value="${books.getId()}" id="bookId">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>相关信息</legend>
</fieldset>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li class="layui-this">借阅信息</li>
        <li>借阅本书的人还借过</li>
        <li>收藏本书的人还收藏过</li>
        <li>相关书评</li>
    </ul>
    <div class="layui-tab-content" style="height: 200px;">
        <div class="layui-tab-item layui-show">
            <table class="layui-table" lay-even="" lay-skin="nob">
                <tr>
                    <td>登录号</td>
                    <td>中图分类号</td>
                    <td>状态</td>
                </tr>
                <tr th:each="i:${same}">
                    <td th:text="${i.getId()}"></td>
                    <td th:text="${i.getClassification()}"></td>
                    <td th:text="${i.getBorrown()} == true?'已借出':'可借'"></td>
                </tr>
            </table>
        </div>
        <div class="layui-tab-item">
            <table class="layui-table" lay-even="" lay-skin="nob">
                <tr>
                    <td>登录号</td>
                    <td>书名</td>
                    <td>作者</td>
                    <td>出版社</td>
                    <td>出版日期</td>
                    <td>评分</td>
                </tr>
                <tr th:each="i:${sameBorrow}">
                    <td th:text="${i.getId()}"></td>
                    <td th:text="${i.getName()}"></td>
                    <td th:text="${i.getAuthor()}"></td>
                    <td th:text="${i.getPublishingHouse()}"></td>
                    <td th:text="${i.getPublishDate()}"></td>
                    <td th:text="${i.getScore()}"></td>
                </tr>
            </table>
        </div>
        <div class="layui-tab-item">
            <table class="layui-table" lay-even="" lay-skin="nob">
                <tr>
                    <td>登录号</td>
                    <td>书名</td>
                    <td>作者</td>
                    <td>出版社</td>
                    <td>出版日期</td>
                    <td>评分</td>
                </tr>
                <tr th:each="i:${sameStar}">
                    <td th:text="${i.getId()}"></td>
                    <td th:text="${i.getName()}"></td>
                    <td th:text="${i.getAuthor()}"></td>
                    <td th:text="${i.getPublishingHouse()}"></td>
                    <td th:text="${i.getPublishDate()}"></td>
                    <td th:text="${i.getScore()}"></td>
                </tr>
            </table>
        </div>
        <div class="layui-tab-item">
            <table class="layui-table" lay-even="" lay-skin="nob">
                <tr>
                    <td>评论人</td>
                    <td>评论内容</td>
                    <td>评分</td>
                </tr>
                <tr th:each="i:${commentList}">
                    <td th:text="${i.getBorrowerName()}"></td>
                    <td th:text="${i.getContent()}"></td>
                    <td th:text="${i.getScore()}"></td>
                </tr>
            </table>
        </div>
    </div>
</div>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>评论（若已经评论过此书籍则会修改评论）</legend>
</fieldset>
<form class="layui-form" action="" >
    <div class="layui-form-item">
        <label class="layui-form-label">评论编号</label>
        <div class="layui-input-block">
            <input type="text" name="id" disabled="disabled" autocomplete="off" class="layui-input" th:value="${comment?.getId()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">评论内容</label>
        <div class="layui-input-block">
            <input type="text" name="content" lay-verify="required" autocomplete="off" class="layui-input" th:value="${comment?.getContent()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">评分</label>
        <div class="layui-input-block">
            <input type="hidden" th:value="${comment?.getScore()}" id="sc">
            <div id="score" name="score" class="demo-slider"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="update1">评论</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <button data-method="star" class="layui-btn" id="star">收藏</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'slider'], function (){
        var form = layui.form, $ = layui.jquery,
            slider = layui.slider,
            layer = layui.layer;
        var score = document.getElementById('sc').value;
        form.on('submit(update1)', function (data) {
            data = data.field;
            data["score"] = score;
            data["bookId"] = document.getElementById('bookId').value;
            data["bookName"] = document.getElementById('bookName').value;
            $.ajax({
                url:"/addComment",
                type:"POST",
                data:data,
                success:function (result){
                    if (result.code==200){
                        layer.msg("评论成功",{
                            icon:6,
                            time:500
                        });
                    }else {layer.msg(result.msg);}
                }
            });
            return false;
        });
        slider.render({
            elem: '#score',
            value: document.getElementById('sc').value,
            input: true,
            change: function(value){
                console.log(value) //动态获取滑块数值
                //do something
                score = value;
            }
        });
        $('#star').on('click',function (){
            var data = {
                'bookId':document.getElementById('bookId').value,
                'bookName':document.getElementById('bookName').value
            }
            $.ajax({
                url:"/starBook",
                type:"POST",
                data:data,
                success:function (result){
                    if (result.code==200){
                        layer.msg("收藏成功",{
                            icon:6,
                            time:500
                        });
                    }else {layer.msg(result.msg);}
                }
            });
            return false;
        })
        form.verify({
            password:function (value, item){
                if(!/[0-9a-zA-Z]{6,9}/.test(value)){
                    return "密码格式错误";
                }
            },
        })
    })
</script>
</body>
</html>